package com.nuc.bigdata.api.controller;

import com.nuc.bigdata.annotation.ResponseResult;
import com.nuc.bigdata.app.service.UserService;
import com.nuc.bigdata.domain.entity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 用户controller与前端交互
 * @author JackLuo
 * @date 2019/10/31
 */
@RestController
@RequestMapping("/front")
@CrossOrigin
public class UserController {
    private final UserService service;

    @Autowired
    public UserController(UserService service) {
        this.service = service;
    }

    /**
     * 用户登录，使用json格式
     * @param user 用户实体类json
     * @return 这里经过ResponseResult注解包装，返回的是Result类型，为了能兼容Service返回类型，就使用了Object类型
     * @throws Exception
     */
    @PostMapping("/user")
    @ResponseResult
    public Object toLogin(@RequestBody User user) throws Exception {
        return service.toLogin(user);
    }

    /**
     * 注册用户
     * @param user 用户实体类json
     * @return 这里经过ResponseResult注解包装，返回的是Result类型，为了能兼容Service返回类型，就使用了Object类型
     * @throws Exception
     */
    @PostMapping("/user/add")
    @ResponseResult
    public Object signUp(@RequestBody User user) throws Exception {
        return service.signUp(user);
    }
}
